package Operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperetion implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的书籍:");
        String name = scanner.nextLine();
        int n = bookList.getBooknum();
        boolean found = true;
        for (int i = 0; i < n; i++) {
            if (name.equals(bookList.getBooks()[i].getName())) {
                System.out.println("删除了" + name + "!");
                bookList.DelBook(i);
                for(int j = i;j < bookList.getBooknum();j++){
                    bookList.getBooks()[j] = bookList.getBooks()[j + 1];
                }
                bookList.setBooknum(bookList.getBooknum() - 1);
                found = false;
                break;
            }
        }
        if(found){
            System.out.println("对不起，你本来就没有这本书！");
        }


    }
}
